// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import axios from 'axios'
/*原型链*/
Vue.prototype.axios = axios;

/*状态管理*/
import Vuex from 'vuex'

Vue.config.productionTip = false

Vue.use(ElementUI);
/*登陆成功之后记录信息*/
Vue.use(Vuex);

/*通过路由判断是否登陆*/
/*在此检查登陆信息*/
router.beforeEach((to,from,next)=>{
  let isLogin =sessionStorage.getItem("isLogin");
  if(to.path=="/logout"){
    sessionStorage.clear();
    next({path:"/login"});
  }
  /*去登陆页面 判断已经登陆 跳到首页*/
  else if(to.path =="/login"){
    if(isLogin=="true"){
      next({path:"/main"});
    }
  }
  else if(isLogin==null){
    /*说明没登陆*/
    next({path:"/login"});
  }
  console.log("触发路由")
  next();
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>',
  router,
  render: h => h(App)
})
